package com.aysafety.iotdataplatformclient.cron;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.aysafety.core.common.DateUtils;
import com.aysafety.core.common.DtoToMapUtils;
import com.aysafety.core.model.*;
import com.aysafety.core.socketdto.*;
import com.aysafety.iotdataplatformclient.acousticEmissionIntensity.services.AcousticEmissionIntensityService;
import com.aysafety.iotdataplatformclient.configurer.IotDataPlatformClient;
import com.aysafety.iotdataplatformclient.configurer.ParadoxDriverForMicroseismConfig;
import com.aysafety.iotdataplatformclient.currentBreaker.services.CurrentBreakerService;
import com.aysafety.iotdataplatformclient.electromagneticIntensity.services.ElectromagneticIntensityService;
import com.aysafety.iotdataplatformclient.electromagneticPulse.services.ElectromagneticPulseService;
import com.aysafety.iotdataplatformclient.gas.services.GasService;
import com.aysafety.iotdataplatformclient.geosound.services.GeosoundService;
import com.aysafety.iotdataplatformclient.hydraulicSupport.services.HydraulicSupportService;
import com.aysafety.iotdataplatformclient.microseism.services.MicroseismService;
import com.aysafety.iotdataplatformclient.sonicPulse.services.SonicPulseService;
import com.aysafety.iotdataplatformclient.winds.services.WindsService;

@Component
@ConfigurationProperties("iotnettyserver")
public class NettyScheduled {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private int port;

    private String host;

    private String clientId;

    private Map<String, Object> cron;

    private int prePage = 200;

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getclientId() {
        return clientId;
    }

    public void setclientId(String clientId) {
        this.clientId = clientId;
    }

    public Map<String, Object> getCron() {
        return cron;
    }

    public void setCron(Map<String, Object> cron) {
        this.cron = cron;
    }

    public int getPrePage() {
        return prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    @Autowired
    IotDataPlatformClient iotDataPlatformClient;

    @Autowired
    MicroseismService microseismService;

    @Autowired
    HydraulicSupportService hydraulicSupportService;

    @Autowired
    GeosoundService geosoundService;

    @Autowired
    AcousticEmissionIntensityService acousticEmissionIntensityService;

    @Autowired
    CurrentBreakerService currentBreakerService;

    @Autowired
    ElectromagneticIntensityService electromagneticIntensityService;

    @Autowired
    ElectromagneticPulseService electromagneticPulseService;

    @Autowired
    GasService gasService;

    @Autowired
    SonicPulseService sonicPulseService;

    @Autowired
    WindsService windsService;

    @Autowired
    ParadoxDriverForMicroseismConfig pdMicroseismConfig;

    @Scheduled(cron = "*/3 * * * * ?")
    public void syncMicroseism() {
        if (this.cron.containsKey("syncmicroseism") && Boolean.valueOf(this.cron.get("syncmicroseism").toString())) {
            if (this.cron.containsKey("microseismdatasorce")
                && this.cron.get("microseismdatasorce").toString().equals("paradox")) {
                this.syncParadoxMicroseism();
            } else if (this.cron.containsKey("microseismdatasorce")
                && this.cron.get("microseismdatasorce").toString().equals("mssql")) {
                this.syncMssqlMicroseism();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("微震同步未开启...");
        }
    }


    @Scheduled(cron = "0 26 22 * * ?")
    public void importMicroseism() {
        if (this.cron.containsKey("importmicroseism")
            && Boolean.valueOf(this.cron.get("importmicroseism").toString())) {
            if (this.cron.containsKey("microseismdatasorce")
                && this.cron.get("microseismdatasorce").toString().equals("paradox")) {
                this.importParadoxMicroseism();
            } else if (this.cron.containsKey("microseismdatasorce")
                && this.cron.get("microseismdatasorce").toString().equals("mssql")) {
                this.importMssqlMicroseism();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("微震数据导入同步未开启...");
        }
    }

    @Scheduled(cron = "0 26 22 * * ?")
    public void importHydraulicSupport() {
        if (this.cron.containsKey("importhydraulicsupport")
            && Boolean.valueOf(this.cron.get("importhydraulicsupport").toString())) {
            if (this.cron.containsKey("hydraulicsupportdatasorce")
                && this.cron.get("hydraulicsupportdatasorce").toString().equals("mssql")) {
                this.importMssqlHydraulicSupport();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("液压支架数据导入同步未开启...");
        }
    }

    @Scheduled(cron = "*/3 * * * * ?")
    public void syncHydraulicSupport() {
        if (this.cron.containsKey("synchydraulicsupport")
            && Boolean.valueOf(this.cron.get("synchydraulicsupport").toString())) {
            if (this.cron.containsKey("hydraulicsupportdatasorce")
                && this.cron.get("hydraulicsupportdatasorce").toString().equals("mssql")) {
                this.syncMssqlHydraulicSupport();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("液压支架同步未开启...");
        }
    }

    @Scheduled(cron = "0 26 22 * * ?")
    public void importGeosound() {
        if (this.cron.containsKey("importgeosound") && Boolean.valueOf(this.cron.get("importgeosound").toString())) {
            if (this.cron.containsKey("geosounddatasorce")
                && this.cron.get("geosounddatasorce").toString().equals("mssql")) {
                this.importMssqlGeosound();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("地音数据导入同步未开启...");
        }
    }

    @Scheduled(cron = "*/3 * * * * ?")
    public void syncGeosound() {
        if (this.cron.containsKey("syncgeosound") && Boolean.valueOf(this.cron.get("syncgeosound").toString())) {
            if (this.cron.containsKey("geosounddatasorce")
                && this.cron.get("geosounddatasorce").toString().equals("mssql")) {
                this.syncMssqlGeosound();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("地音同步未开启...");
        }
    }

    private void syncParadoxMicroseism() {
        Map<String, Object> sendData = null;
        try {
            int page = 0;
            int start = 0;
            MicroseismDTO microseismDTO = new MicroseismDTO(this.clientId);
            String jdbcPath = pdMicroseismConfig.getJdbcPath();
            String tableId = pdMicroseismConfig.getTableId();
            String charset = pdMicroseismConfig.getTableId();
            String locale = pdMicroseismConfig.getTableId();
            MicroseismModel data = microseismService.readData(jdbcPath, tableId, charset, locale);
            microseismDTO.setData(data);
            sendData = DtoToMapUtils.DTOToMap(microseismDTO);
            sendData.put("page", page);
            sendData.put("start", start);
            sendData.put("clientId", this.clientId);
            logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(page) + ".:."
                + String.valueOf(start));
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            sendData = DtoToMapUtils.DTOToMap(errorDTO);
        }
        iotDataPlatformClient.setParams(this.getHost(), this.getPort());
        iotDataPlatformClient.sendData(sendData);
    }

    public void syncMssqlMicroseism() {
        logger.info("正在启动syncMicroseism...");
        Map<String, Object> sendData = null;
        try {
            int page = 0;
            int start = 0;
            MicroseismDTO microseismDTO = new MicroseismDTO(this.clientId);
            MicroseismModel data = microseismService.readData();
            microseismDTO.setData(data);
            sendData = DtoToMapUtils.DTOToMap(microseismDTO);
            sendData.put("page", page);
            sendData.put("start", start);
            sendData.put("clientId", this.clientId);
            logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(page) + ".:."
                + String.valueOf(start));
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            sendData = DtoToMapUtils.DTOToMap(errorDTO);
        }
        iotDataPlatformClient.setParams(this.getHost(), this.getPort());
        iotDataPlatformClient.sendData(sendData);
        logger.info("完成启动syncMicroseism...");
    }

    private void importParadoxMicroseism() {

    }

    public void importMssqlMicroseism() {
        logger.info("正在启动importMicroseism...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            MicroseismDTO microseismDTO = new MicroseismDTO(this.clientId);
            microseismDTO.setDataType("histroy");
            conditions.put("startTime", DateUtils.getCurrentMonthStartTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("endTime", DateUtils.getCurrentEndTimeFirstDay("yyyy-MM-dd HH:mm:ss"));
            int dataCount = microseismService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<MicroseismModel> readHistroyDataData =
                    microseismService.readHistroyData(conditions, start, this.prePage);
                microseismDTO.setData(readHistroyDataData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(microseismDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动importMicroseism...");
    }

    private void importMssqlHydraulicSupport() {
        logger.info("正在启动importMssqlHydraulicSupport...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            HydraulicSupportDTO hydraulicSupportDTO = new HydraulicSupportDTO(this.clientId);
            hydraulicSupportDTO.setDataType("histroy");
            conditions.put("startTime", DateUtils.getCurrentMonthStartTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("endTime", DateUtils.getCurrentEndTimeFirstDay("yyyy-MM-dd HH:mm:ss"));
            int dataCount = hydraulicSupportService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<HydraulicSupportModel> readHistroyData =
                    hydraulicSupportService.readHistroyData(conditions, start, this.prePage);
                hydraulicSupportDTO.setData(readHistroyData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(hydraulicSupportDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动importMssqlHydraulicSupport...");
    }

    private void syncMssqlHydraulicSupport() {
        logger.info("正在启动syncMssqlHydraulicSupport...");
        Map<String, Object> sendData = null;
        Map<String, Object> conditions = new HashMap<String, Object>();
        try {
            int page = 0;
            int start = 0;
            conditions.put("startTime", DateUtils.getCurrentTimeFirstSecond("yyyy-MM-dd HH:mm:ss", 30));
            conditions.put("endTime", DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
            HydraulicSupportDTO hydraulicSupportDTO = new HydraulicSupportDTO(this.clientId);
            List<HydraulicSupportModel> data = hydraulicSupportService.readData(conditions);
            hydraulicSupportDTO.setData(data);
            sendData = DtoToMapUtils.DTOToMap(hydraulicSupportDTO);
            sendData.put("page", page);
            sendData.put("start", start);
            sendData.put("clientId", this.clientId);
            logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(page) + ".:."
                + String.valueOf(start));
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            sendData = DtoToMapUtils.DTOToMap(errorDTO);
        }
        iotDataPlatformClient.setParams(this.getHost(), this.getPort());
        iotDataPlatformClient.sendData(sendData);
        logger.info("完成启动syncMssqlHydraulicSupport...");
    }

    private void importMssqlGeosound() {
        logger.info("正在启动importMssqlGeosound...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            GeosoundDTO geosoundDTO = new GeosoundDTO(this.clientId);
            geosoundDTO.setDataType("histroy");
            conditions.put("startTime", DateUtils.getCurrentMonthStartTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("endTime", DateUtils.getCurrentEndTimeFirstDay("yyyy-MM-dd HH:mm:ss"));
            int dataCount = geosoundService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<GeosoundModel> readHistroyData = geosoundService.readHistroyData(conditions, start, this.prePage);
                geosoundDTO.setData(readHistroyData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(geosoundDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动importMssqlGeosound...");
    }

    private void syncMssqlGeosound() {
        logger.info("正在启动syncMssqlGeosound...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            GeosoundDTO geosoundDTO = new GeosoundDTO(this.clientId);
            conditions.put("startTime", DateUtils.getCurrentTimeFirstSecond("yyyy-MM-dd HH:mm:ss", 30));
            conditions.put("endTime", DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
            int dataCount = geosoundService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<GeosoundModel> readHistroyDataData =
                    geosoundService.readHistroyData(conditions, start, this.prePage);
                geosoundDTO.setData(readHistroyDataData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(geosoundDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动syncMssqlGeosound...");
    }

    @Scheduled(cron = "0 26 22 * * ?")
    public void importAcousticEmissionIntensity() {
        if (this.cron.containsKey("importacousticemissionintensity")
            && Boolean.valueOf(this.cron.get("importacousticemissionintensity").toString())) {
            if (this.cron.containsKey("acousticemissionintensitydatasorce")
                && this.cron.get("acousticemissionintensitydatasorce").toString().equals("mssql")) {
                this.importMssqlAcousticEmissionIntensity();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("声发射强度数据导入同步未开启...");
        }
    }

    @Scheduled(cron = "*/3 * * * * ?")
    public void syncAcousticEmissionIntensity() {
        if (this.cron.containsKey("syncacousticemissionintensity")
            && Boolean.valueOf(this.cron.get("syncacousticemissionintensity").toString())) {
            if (this.cron.containsKey("acousticemissionintensitydatasorce")
                && this.cron.get("acousticemissionintensitydatasorce").toString().equals("mssql")) {
                this.syncMssqlAcousticEmissionIntensity();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("声发射强度同步未开启...");
        }
    }

    private void importMssqlAcousticEmissionIntensity() {
        logger.info("正在启动importMssqlAcousticEmissionIntensity...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            AcousticEmissionIntensityDTO acousticEmissionIntensityDTO = new AcousticEmissionIntensityDTO(this.clientId);
            acousticEmissionIntensityDTO.setDataType("histroy");
            conditions.put("startTime", DateUtils.getCurrentMonthStartTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("endTime", DateUtils.getCurrentEndTimeFirstDay("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "声发射强度");
            int dataCount = acousticEmissionIntensityService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<AcousticEmissionIntensityModel> readHistroyData =
                    acousticEmissionIntensityService.readHistroyData(conditions, start, this.prePage);
                acousticEmissionIntensityDTO.setData(readHistroyData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(acousticEmissionIntensityDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动importMssqlAcousticEmissionIntensity...");
    }

    private void syncMssqlAcousticEmissionIntensity() {
        logger.info("正在启动syncMssqlAcousticEmissionIntensity...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            AcousticEmissionIntensityDTO acousticEmissionIntensityDTO = new AcousticEmissionIntensityDTO(this.clientId);
            conditions.put("startTime", DateUtils.getCurrentTimeFirstSecond("yyyy-MM-dd HH:mm:ss", 30));
            conditions.put("endTime", DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "声发射强度");
            int dataCount = acousticEmissionIntensityService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<AcousticEmissionIntensityModel> readHistroyDataData =
                    acousticEmissionIntensityService.readHistroyData(conditions, start, this.prePage);
                acousticEmissionIntensityDTO.setData(readHistroyDataData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(acousticEmissionIntensityDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动syncMssqlAcousticEmissionIntensity...");
    }

    @Scheduled(cron = "0 26 22 * * ?")
    public void importCurrentBreaker() {
        if (this.cron.containsKey("importcurrentbreaker")
            && Boolean.valueOf(this.cron.get("importcurrentbreaker").toString())) {
            if (this.cron.containsKey("currentbreakerdatasorce")
                && this.cron.get("currentbreakerdatasorce").toString().equals("mssql")) {
                this.importMssqlCurrentBreaker();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("电流开关量数据导入同步未开启...");
        }
    }

    @Scheduled(cron = "*/3 * * * * ?")
    public void syncCurrentBreaker() {
        if (this.cron.containsKey("synccurrentbreaker")
            && Boolean.valueOf(this.cron.get("synccurrentbreaker").toString())) {
            if (this.cron.containsKey("currentbreakerdatasorce")
                && this.cron.get("currentbreakerdatasorce").toString().equals("mssql")) {
                this.syncMssqlCurrentBreaker();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("电流开关量同步未开启...");
        }
    }

    private void importMssqlCurrentBreaker() {
        logger.info("正在启动importMssqlCurrentBreaker...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            CurrentBreakerDTO currentBreakerDTO = new CurrentBreakerDTO(this.clientId);
            currentBreakerDTO.setDataType("histroy");
            conditions.put("startTime", DateUtils.getCurrentMonthStartTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("endTime", DateUtils.getCurrentEndTimeFirstDay("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "电流开关量");
            int dataCount = currentBreakerService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<CurrentBreakerModel> readHistroyData =
                    currentBreakerService.readHistroyData(conditions, start, this.prePage);
                currentBreakerDTO.setData(readHistroyData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(currentBreakerDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动importMssqlCurrentBreaker...");
    }

    private void syncMssqlCurrentBreaker() {
        logger.info("正在启动syncMssqlCurrentBreaker...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            CurrentBreakerDTO currentBreakerDTO = new CurrentBreakerDTO(this.clientId);
            conditions.put("startTime", DateUtils.getCurrentTimeFirstSecond("yyyy-MM-dd HH:mm:ss", 30));
            conditions.put("endTime", DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "电流开关量");
            int dataCount = currentBreakerService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<CurrentBreakerModel> readHistroyDataData =
                    currentBreakerService.readHistroyData(conditions, start, this.prePage);
                currentBreakerDTO.setData(readHistroyDataData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(currentBreakerDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动syncMssqlCurrentBreaker...");
    }

    @Scheduled(cron = "0 26 22 * * ?")
    public void importElectromagneticIntensity() {
        if (this.cron.containsKey("importelectromagneticintensity")
            && Boolean.valueOf(this.cron.get("importelectromagneticintensity").toString())) {
            if (this.cron.containsKey("electromagneticintensitydatasorce")
                && this.cron.get("electromagneticintensitydatasorce").toString().equals("mssql")) {
                this.importMssqlElectromagneticIntensity();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("电磁强度数据导入同步未开启...");
        }
    }

    @Scheduled(cron = "*/3 * * * * ?")
    public void syncElectromagneticIntensity() {
        if (this.cron.containsKey("syncelectromagneticintensity")
            && Boolean.valueOf(this.cron.get("syncelectromagneticintensity").toString())) {
            if (this.cron.containsKey("electromagneticintensitydatasorce")
                && this.cron.get("electromagneticintensitydatasorce").toString().equals("mssql")) {
                this.syncMssqlElectromagneticIntensity();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("电磁强度同步未开启...");
        }
    }

    private void importMssqlElectromagneticIntensity() {
        logger.info("正在启动importMssqlElectromagneticIntensity...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            ElectromagneticIntensityDTO electromagneticIntensityDTO = new ElectromagneticIntensityDTO(this.clientId);
            electromagneticIntensityDTO.setDataType("histroy");
            conditions.put("startTime", DateUtils.getCurrentMonthStartTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("endTime", DateUtils.getCurrentEndTimeFirstDay("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "电磁强度");
            int dataCount = electromagneticIntensityService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<ElectromagneticIntensityModel> readHistroyData =
                    electromagneticIntensityService.readHistroyData(conditions, start, this.prePage);
                electromagneticIntensityDTO.setData(readHistroyData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(electromagneticIntensityDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动importMssqlElectromagneticIntensity...");
    }

    private void syncMssqlElectromagneticIntensity() {
        logger.info("正在启动syncMssqlElectromagneticIntensity...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            ElectromagneticIntensityDTO electromagneticIntensityDTO = new ElectromagneticIntensityDTO(this.clientId);
            conditions.put("startTime", DateUtils.getCurrentTimeFirstSecond("yyyy-MM-dd HH:mm:ss", 30));
            conditions.put("endTime", DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "电磁强度");
            int dataCount = electromagneticIntensityService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<ElectromagneticIntensityModel> readHistroyDataData =
                    electromagneticIntensityService.readHistroyData(conditions, start, this.prePage);
                electromagneticIntensityDTO.setData(readHistroyDataData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(electromagneticIntensityDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动syncMssqlElectromagneticIntensity...");
    }

    @Scheduled(cron = "0 26 22 * * ?")
    public void importElectromagneticPulse() {
        if (this.cron.containsKey("importelectromagneticpulse")
            && Boolean.valueOf(this.cron.get("importelectromagneticpulse").toString())) {
            if (this.cron.containsKey("electromagneticpulsedatasorce")
                && this.cron.get("electromagneticpulsedatasorce").toString().equals("mssql")) {
                this.importMssqlElectromagneticPulse();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("电磁脉冲数据导入同步未开启...");
        }
    }

    @Scheduled(cron = "*/3 * * * * ?")
    public void syncElectromagneticPulse() {
        if (this.cron.containsKey("syncelectromagneticpulse")
            && Boolean.valueOf(this.cron.get("syncelectromagneticpulse").toString())) {
            if (this.cron.containsKey("electromagneticpulsedatasorce")
                && this.cron.get("electromagneticpulsedatasorce").toString().equals("mssql")) {
                this.syncMssqlElectromagneticPulse();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("电磁脉冲同步未开启...");
        }
    }

    private void importMssqlElectromagneticPulse() {
        logger.info("正在启动importMssqlElectromagneticPulse...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            ElectromagneticPulseDTO electromagneticPulseDTO = new ElectromagneticPulseDTO(this.clientId);
            electromagneticPulseDTO.setDataType("histroy");
            conditions.put("startTime", DateUtils.getCurrentMonthStartTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("endTime", DateUtils.getCurrentEndTimeFirstDay("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "电磁脉冲");
            int dataCount = electromagneticPulseService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<ElectromagneticPulseModel> readHistroyData =
                    electromagneticPulseService.readHistroyData(conditions, start, this.prePage);
                electromagneticPulseDTO.setData(readHistroyData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(electromagneticPulseDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动importMssqlElectromagneticPulse...");
    }

    private void syncMssqlElectromagneticPulse() {
        logger.info("正在启动syncMssqlElectromagneticPulse...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            ElectromagneticPulseDTO electromagneticPulseDTO = new ElectromagneticPulseDTO(this.clientId);
            conditions.put("startTime", DateUtils.getCurrentTimeFirstSecond("yyyy-MM-dd HH:mm:ss", 30));
            conditions.put("endTime", DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "电磁脉冲");
            int dataCount = electromagneticPulseService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<ElectromagneticPulseModel> readHistroyDataData =
                    electromagneticPulseService.readHistroyData(conditions, start, this.prePage);
                electromagneticPulseDTO.setData(readHistroyDataData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(electromagneticPulseDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动syncMssqlElectromagneticPulse...");
    }

    @Scheduled(cron = "0 26 22 * * ?")
    public void importGas() {
        if (this.cron.containsKey("importgas") && Boolean.valueOf(this.cron.get("importgas").toString())) {
            if (this.cron.containsKey("gasdatasorce") && this.cron.get("gasdatasorce").toString().equals("mssql")) {
                this.importMssqlGas();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("瓦斯数据导入同步未开启...");
        }
    }

    @Scheduled(cron = "*/3 * * * * ?")
    public void syncGas() {
        if (this.cron.containsKey("syncgas") && Boolean.valueOf(this.cron.get("syncgas").toString())) {
            if (this.cron.containsKey("gasdatasorce") && this.cron.get("gasdatasorce").toString().equals("mssql")) {
                this.syncMssqlGas();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("瓦斯同步未开启...");
        }
    }

    private void importMssqlGas() {
        logger.info("正在启动importMssqlGas...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            GasDTO gasDTO = new GasDTO(this.clientId);
            gasDTO.setDataType("histroy");
            conditions.put("startTime", DateUtils.getCurrentMonthStartTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("endTime", DateUtils.getCurrentEndTimeFirstDay("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "瓦斯");
            int dataCount = gasService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<GasModel> readHistroyData = gasService.readHistroyData(conditions, start, this.prePage);
                gasDTO.setData(readHistroyData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(gasDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动importMssqlGas...");
    }

    private void syncMssqlGas() {
        logger.info("正在启动syncMssqlGas...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            GasDTO gasDTO = new GasDTO(this.clientId);
            conditions.put("startTime", DateUtils.getCurrentTimeFirstSecond("yyyy-MM-dd HH:mm:ss", 30));
            conditions.put("endTime", DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "瓦斯");
            int dataCount = gasService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<GasModel> readHistroyDataData = gasService.readHistroyData(conditions, start, this.prePage);
                gasDTO.setData(readHistroyDataData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(gasDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动syncMssqlGas...");
    }

    @Scheduled(cron = "0 26 22 * * ?")
    public void importSonicPulse() {
        if (this.cron.containsKey("importsonicpulse")
            && Boolean.valueOf(this.cron.get("importsonicpulse").toString())) {
            if (this.cron.containsKey("sonicpulsedatasorce")
                && this.cron.get("sonicpulsedatasorce").toString().equals("mssql")) {
                this.importMssqlSonicPulse();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("声波脉冲数据导入同步未开启...");
        }
    }

    @Scheduled(cron = "*/3 * * * * ?")
    public void syncSonicPulse() {
        if (this.cron.containsKey("syncsonicpulse") && Boolean.valueOf(this.cron.get("syncsonicpulse").toString())) {
            if (this.cron.containsKey("sonicpulsedatasorce")
                && this.cron.get("sonicpulsedatasorce").toString().equals("mssql")) {
                this.syncMssqlSonicPulse();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("声波脉冲同步未开启...");
        }
    }

    private void importMssqlSonicPulse() {
        logger.info("正在启动importMssqlSonicPulse...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            SonicPulseDTO sonicPulseDTO = new SonicPulseDTO(this.clientId);
            sonicPulseDTO.setDataType("histroy");
            conditions.put("startTime", DateUtils.getCurrentMonthStartTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("endTime", DateUtils.getCurrentEndTimeFirstDay("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "声波脉冲");
            int dataCount = sonicPulseService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<SonicPulseModel> readHistroyData =
                    sonicPulseService.readHistroyData(conditions, start, this.prePage);
                sonicPulseDTO.setData(readHistroyData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(sonicPulseDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动importMssqlSonicPulse...");
    }

    private void syncMssqlSonicPulse() {
        logger.info("正在启动syncMssqlSonicPulse...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            SonicPulseDTO sonicPulseDTO = new SonicPulseDTO(this.clientId);
            conditions.put("startTime", DateUtils.getCurrentTimeFirstSecond("yyyy-MM-dd HH:mm:ss", 30));
            conditions.put("endTime", DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "声波脉冲");
            int dataCount = sonicPulseService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<SonicPulseModel> readHistroyDataData =
                    sonicPulseService.readHistroyData(conditions, start, this.prePage);
                sonicPulseDTO.setData(readHistroyDataData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(sonicPulseDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动syncMssqlSonicPulse...");
    }

    @Scheduled(cron = "30 44 17 * * ?")
    public void importWinds() {
        if (this.cron.containsKey("importwinds") && Boolean.valueOf(this.cron.get("importwinds").toString())) {
            if (this.cron.containsKey("windsdatasorce") && this.cron.get("windsdatasorce").toString().equals("mssql")) {
                this.importMssqlWinds();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("风速数据导入同步未开启...");
        }
    }

    @Scheduled(cron = "*/3 * * * * ?")
    public void syncWinds() {
        if (this.cron.containsKey("syncwinds") && Boolean.valueOf(this.cron.get("syncwinds").toString())) {
            if (this.cron.containsKey("windsdatasorce") && this.cron.get("windsdatasorce").toString().equals("mssql")) {
                this.syncMssqlWinds();
            } else {
                logger.info("未匹配数据源...");
            }
        } else {
            logger.info("风速同步未开启...");
        }
    }

    private void importMssqlWinds() {
        logger.info("正在启动importMssqlWinds...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            WindsDTO windsDTO = new WindsDTO(this.clientId);
            windsDTO.setDataType("histroy");
            conditions.put("startTime", DateUtils.getCurrentMonthStartTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("endTime", DateUtils.getCurrentEndTimeFirstDay("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "风速");
            int dataCount = windsService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<WindsModel> readHistroyData = windsService.readHistroyData(conditions, start, this.prePage);
                windsDTO.setData(readHistroyData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(windsDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动importMssqlWinds...");
    }

    private void syncMssqlWinds() {
        logger.info("正在启动syncMssqlWinds...");
        try {
            Map<String, Object> conditions = new HashMap<String, Object>();
            WindsDTO windsDTO = new WindsDTO(this.clientId);
            conditions.put("startTime", DateUtils.getCurrentTimeFirstSecond("yyyy-MM-dd HH:mm:ss", 30));
            conditions.put("endTime", DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss"));
            conditions.put("type", "风速");
            int dataCount = windsService.readHistroyDataCount(conditions);
            int page = dataCount % this.prePage == 0 ? dataCount / this.prePage : (dataCount / this.prePage) + 1;
            for (int i = 0; i <= page; i++) {
                int start = this.prePage * i;
                List<WindsModel> readHistroyDataData = windsService.readHistroyData(conditions, start, this.prePage);
                windsDTO.setData(readHistroyDataData);
                Map<String, Object> sendData = DtoToMapUtils.DTOToMap(windsDTO);
                sendData.put("page", i);
                sendData.put("start", start);
                sendData.put("clientId", this.clientId);
                logger.info(DateUtils.getCurrentTime("yyyy-MM-dd HH:mm:ss") + ".:." + String.valueOf(i) + ".:."
                    + String.valueOf(start));
                iotDataPlatformClient.setParams(this.getHost(), this.getPort());
                iotDataPlatformClient.sendData(sendData);
            }
        } catch (Exception e) {
            logger.error("数据发送异常:", e);
            Map<String, Object> errorData = null;
            ErrorDTO errorDTO = new ErrorDTO(this.clientId);
            errorDTO.setDataType("Exception");
            errorDTO.setData(e.toString());
            errorData = DtoToMapUtils.DTOToMap(errorDTO);
            iotDataPlatformClient.setParams(this.getHost(), this.getPort());
            iotDataPlatformClient.sendData(errorData);
        }
        logger.info("完成启动syncMssqlWinds...");
    }

}
